import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_enjoy_plus/apis/home.dart';
import 'package:flutter_enjoy_plus/pages/Home/components/home_list.dart';
import 'package:flutter_enjoy_plus/pages/Home/components/home_nav.dart';
import 'package:flutter_enjoy_plus/utils/TokenManageer.dart';
import 'package:flutter_enjoy_plus/utils/toast.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  List announcementList = [];

  Timer? timer;
  int countDown = 60;

  @override
  void initState() {
    super.initState();
    getAnnouncementList();
  }

  // 获取社区公告
  getAnnouncementList() async {
    // 请求社区公告列表
    final res = await HomeApi.getAnnouncementList();
    // PromptAction.showSuccess(res.toString());
    // 更新社区公告列表
    setState(() {
      announcementList = res;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: const Color.fromARGB(40, 85, 145, 175),
        appBar: AppBar(
          title: TextButton(
            onPressed: () {
              Navigator.pushNamed(context, '/tanchuang');
            },
            child: const Text(
              '享+社区',
              style: TextStyle(fontSize: 24),
            ),
          ),
          backgroundColor: Colors.transparent,
          centerTitle: true,
        ),
        body: ListView(
          scrollDirection: Axis.vertical,
          padding: const EdgeInsets.all(10),
          children: [
            // 导航条
            HomeNav(),
            const SizedBox(height: 10),
            // 中间广告图
            ClipRRect(
              borderRadius: BorderRadius.circular(10.0),
              child: Image.asset('assets/images/banner@2x.jpg'),
            ),
            // 社区公告，数据父传子
            HomeList(notifyList: announcementList)
          ],
        ));
  }
}
